﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Text;

using E.Web.UI.Page;
using E.BLL;
using E.Model;
using E.Enum;

using X.Common;
using E.Web.Common;
using System.Web.Script.Serialization;

namespace E.Web.Teacher.UI
{
    public class AjaxPage : TeacherBasePage
    {
        public AjaxPage()
        {
            string type = XRequest.GetString("t");

            switch (type)
            {
                case "setLang":
                    SetLanguage(XRequest.GetInt("langid", -1));
                    break;
                case "chkLoginID":
                    CheckLoginID(XRequest.GetString("v"));
                    break;
                case "chkIDCard":
                    CheckIDCard(XRequest.GetString("v"), XRequest.GetInt("id", -1));
                    break;
                case "chkTeacherLoginID":
                    CheckTeacherLoginID(XRequest.GetString("v"));
                    break;
                case "getCourseList":
                    GetCourseList(XRequest.GetInt("cid", -1));
                    break;
                case "getCourseListWithCourseID":
                    GetCourseListWithCourseID(XRequest.GetInt("cid", -1));
                    break;
                case "getRelationContent":
                    GetRelationContent(XRequest.GetInt("v", -1));
                    break;
                case "getQuestionCategoryList":
                    GetQuestionCategoryList();
                    break;
                case "getEmptySettingTemplate":
                    GetEmptySettingTemplate(XRequest.GetInt("cid", -1), XRequest.GetInt("courseid", -1), XRequest.GetInt("isquestionrandom", -1), XRequest.GetString("questionIDArr"));
                    break;
                case "getCertificateSettingTemplate":
                    GetCertificateSettingTemplate(XRequest.GetInt("cid", -1), XRequest.GetInt("id", -1), XRequest.GetInt("isquestionrandom", -1), XRequest.GetString("questionIDArr"));
                    break;
                case "getCertificateSurveyReport":
                    GetCertificateSurveyReport(XRequest.GetInt("id", -1));
                    break;
                case "getTotalScore":
                    GetTotalScore(XRequest.GetString("cid"), XRequest.GetString("quantity"));
                    break;
                case "chkCourseName":
                    CheckCourseName(XRequest.GetString("v"), XRequest.GetInt("pid", -1), XRequest.GetInt("id", -1));
                    break;
                case "chkInternalPublicCourseName":
                    CheckInternalPublicCourseName(XRequest.GetString("v"), XRequest.GetInt("pid", -1), XRequest.GetInt("id", -1));
                    break;
                case "chkProjectName":
                    CheckProjectName(XRequest.GetString("v"), XRequest.GetInt("id", -1));
                    break;
                case "chkPublicCourseName":
                    CheckPublicCourseName(XRequest.GetString("v"), XRequest.GetInt("id", -1));
                    break;
                case "chkScoreCategoryName":
                    CheckScoreCategory(XRequest.GetString("v"), XRequest.GetInt("id", -1));
                    break;
                case "getStudentByProject":
                    GetStudentByProject(XRequest.GetString("v"), XRequest.GetString("seleCourseId"));
                    break;
                case "getPublicStudentByProject":
                    GetPublicStudentByProject(XRequest.GetString("v"), XRequest.GetString("seleCourseId"));
                    break;
                case "getUserInfoByUserID":
                    GetUserInfoByUserID(XRequest.GetString("studentIds"));
                    break;
                case "isExistSkillGroupName":
                    IsExistSkillGroupName(XRequest.GetString("name"));
                    break;
                default: break;
            }
        }

        /// <summary>
        /// Ajax判断输入的技能组名称是否已经存在
        /// </summary>
        /// <param name="p"></param>
        private void IsExistSkillGroupName(string p)
        {
            bool isExist = (new CourseBLL()).IsExistSkillGroupName(p);
            StringBuilder result = new StringBuilder(isExist.ToString());
            ResponseXML(result);
        }

        private void GetStudentByProject(String selectProject,String seleCourseId)
        {
            UserBLL bll = new UserBLL();
            UserModel model = new UserModel();
            model.CurrentCertificateID = int.Parse(selectProject);
            //model.CourseID = int.Parse(seleCourseId);
            model.CourseArrayId = seleCourseId;
            model.Email = "";
            model.LoginID = XRequest.GetString("loginId") ;
            model.UserName = "";
            model.AreaID = areaid;
            model.DelFlagInt = 0;
            model.IsPublicInt = 0;
            model.EntryFromDate = XRequest.GetString("entryFromDate");
            model.EntryToDate = XRequest.GetString("entryToDate");
            customerPageSize = int.MaxValue;
            pageIndex = 0;
            IList<UserListModel> userList = bll.GetUnSignUpInternalClassUserListByCondition(model);
            JavaScriptSerializer js = new JavaScriptSerializer();
            string json = js.Serialize(userList);
            ResponseJSON(json);
        }
        /// <summary>
        /// 获取外训学生
        /// </summary>
        /// <param name="selectProject"></param>
        /// <param name="seleCourseId"></param>
        private void GetPublicStudentByProject(String selectProject, String seleCourseId)
        {
            UserBLL bll = new UserBLL();
            UserModel model = new UserModel();
            model.CurrentCertificateID = int.Parse(selectProject);
            model.CourseID = int.Parse(seleCourseId);
            model.CourseArrayId = seleCourseId;
            model.Email = "";
            model.LoginID = XRequest.GetString("loginId");
            model.UserName = "";
            model.AreaID = XRequest.GetInt("seleAreaID", -1);
            model.DelFlagInt = 0;
            model.IsPublicInt = 1;
            model.EntryFromDate = XRequest.GetString("entryFromDate");
            model.EntryToDate = XRequest.GetString("entryToDate");
            customerPageSize = int.MaxValue;
            pageIndex = 0;
            IList<UserListModel> userList = bll.GetUnSignUpPublicClassUserListByCondition(model);
            JavaScriptSerializer js = new JavaScriptSerializer();
            string json = js.Serialize(userList);
            ResponseJSON(json);
        }
        /// <summary>
        /// 获取报名审核的学生列表
        /// </summary>
        /// <param name="studentIDs"></param>
        private void GetUserInfoByUserID(String studentIDs)
        {
            UserBLL bll = new UserBLL();
            UserModel model = new UserModel();
            IList<UserModel> userModelList = new List<UserModel>();
            string[] userIDArr = studentIDs.Split(';');
            foreach (string userID in userIDArr)
            {
                if (userID != "")
                {
                    model = bll.GetUserInfoByUserID(Convert.ToInt32(userID));
                    userModelList.Add(model);
                }
            }
            IList<UserModel> userList = userModelList;
            JavaScriptSerializer js = new JavaScriptSerializer();
            string json = js.Serialize(userList);
            ResponseJSON(json);
        }
        private void SetLanguage(int langid)
        {
            string strRst = "0";
            if (langid != -1)
            {
                strRst = WebCommon.SetLanguageCookie(langid) ? "1" : "0";
            }
            ResponseSimpleXML(strRst);
        }

        private void CheckLoginID(string loginid)
        {
            bool rst = (new UserBLL()).CheckExistLoginID(loginid);
            if (rst)
            {
                ResponseSimpleXML("1");
            }
            else
            {
                ResponseSimpleXML("0");
            }
        }

        private void CheckIDCard(string idcard, int id)
        {
            bool rst = (new UserBLL()).CheckExistIDCard(idcard, id);
            if (rst)
            {
                ResponseSimpleXML("1");
            }
            else
            {
                ResponseSimpleXML("0");
            }
        }

        private void CheckTeacherLoginID(string loginid)
        {
            bool rst = (new TeacherBLL()).CheckExistLoginID(loginid);
            if (rst)
            {
                ResponseSimpleXML("1");
            }
            else
            {
                ResponseSimpleXML("0");
            }
        }

        private void GetCourseList(int certificateid)
        {
            StringBuilder sb = new StringBuilder();
            if (certificateid != -1)
            {
                Dictionary<int, string> list = (new CourseBLL()).GetRelationCourseList(certificateid);
                foreach (KeyValuePair<int, string> kvp in list)
                {
                    sb.Append("<course relationid=\"" + kvp.Key + "\" courseName=\"" + kvp.Value + "\" />");
                }
            }

            ResponseSimpleXML(sb.ToString());
        }

        private void GetCourseListWithCourseID(int certificateid)
        {
            StringBuilder sb = new StringBuilder();
            if (certificateid != -1)
            {
                Dictionary<int, string> list = (new CourseBLL()).GetCourseListByCertificateID(certificateid);
                foreach (KeyValuePair<int, string> kvp in list)
                {
                    sb.Append("<course courseID=\"" + kvp.Key + "\" courseName=\"" + kvp.Value + "\" />");
                }
            }

            ResponseSimpleXML(sb.ToString());
        }

        private void GetRelationContent(int id)
        {
            StringBuilder sb = new StringBuilder();
            Dictionary<int,string> list = new Dictionary<int,string>();
            if (id != -1)
            {
                switch ((EnumExamCategory)id)
                {
                    case EnumExamCategory.CourseExam:
                        list = (new CourseBLL()).GetCourseList();
                        break;
                    case EnumExamCategory.CertificateExam:
                        list = (new CourseBLL()).GetCertificateList();
                        break;
                    default:
                        break;
                }
                if (list.Count > 0)
                {
                    foreach (KeyValuePair<int, string> kvp in list)
                    {
                        sb.Append("<content relationid=\"" + kvp.Key + "\" relationvalue=\"" + kvp.Value + "\" />");
                    }
                }
            }

            ResponseSimpleXML(sb.ToString());
        }

        private void GetQuestionCategoryList()
        {
            StringBuilder sb = new StringBuilder();
            Dictionary<int, string> list = (new QuestionBLL()).GetQuestionCategoryList();

            if (list.Count > 0)
            {
                foreach (KeyValuePair<int, string> kvp in list)
                {
                    sb.Append("<category id=\"" + kvp.Key + "\" name=\"" + kvp.Value + "\" />");
                }
            }
            ResponseSimpleXML(sb.ToString());
        }

        private void GetEmptySettingTemplate(int cid, int courseid, int questiontype, string questionIDs)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<rst>");
            switch ((EnumExamCategory)cid)
            {
                case EnumExamCategory.CourseExam:
                    QuestionBLL bll = new QuestionBLL();
                    Dictionary<int, string> categoryList = bll.GetQuestionCategoryList();
                    IList<QuestionModel> tmplist = null;
                    IList<QuestionModel> tmplist_re = null;
                    IList<int> questionIDList = null;

                    string questionIDArr = string.Empty;

                    if (categoryList.Count > 0)
                    {
                        if (questiontype == 1)
                        {
                            sb.Append("<![CDATA[");
                            sb.Append("<div class=\"data_rows\" style=\"font-weight: bolder;\">\r\n");
                            sb.Append("<div class=\"d_r_qt\">题型</div>");
                            sb.Append("<div class=\"d_r_qx\">&nbsp;</div>\r\n");
                            sb.Append("<div class=\"d_r_qq\">普通题数</div>\r\n");
                            sb.Append("<div class=\"d_r_qq\">必选题数</div>\r\n");
                            sb.Append(" <div class=\"d_r_qo\">必选/全部</div>\r\n");
                            sb.Append("</div>\r\n");
                        }
                        else
                        {
                            if (questionIDs != "")
                            {
                                questionIDList = WebCommon.Convert2IList(questionIDs, ',');
                            }
                            sb.Append("<![CDATA[");
                        }

                        foreach (KeyValuePair<int, string> kvp in categoryList)
                        {

                            if (questiontype == 1)
                            {
                                sb.Append("<div class=\"data_rows\">\r\n");
                                sb.Append("  <div class=\"d_r_qt\">" + kvp.Value + "</div>\r\n");
                                sb.Append("  <div class=\"d_r_qx\"><span class=\"hint\" id=\"total_" + kvp.Key + "\">&nbsp;</span></div>\r\n");
                                sb.Append("  <div class=\"d_r_qq\"><input type=\"text\" id=\"input_" + kvp.Key + "\" name=\"input_" + kvp.Key + "\" class=\"quantityInput\" /></div>\r\n");
                                sb.Append("  <div class=\"d_r_qq\"><input type=\"text\" id=\"input_" + kvp.Key + "_re\" name=\"input_" + kvp.Key + "_re\" class=\"quantityInput\" /></div>\r\n");
                                sb.Append("  <div class=\"d_r_qo\">" + bll.GetAllRequiredQuestionQuantity(courseid, kvp.Key) + "/" + bll.GetAllQuestionQuantity(courseid, kvp.Key) + "</div>\r\n");
                                sb.Append("  <input type=\"hidden\" id=\"qty_" + kvp.Key + "\" name=\"qty_" + kvp.Key + "\" value=\"" + bll.GetAllQuestionQuantity(courseid, kvp.Key) + "\" >");
                                sb.Append("  <input type=\"hidden\" id=\"qty_" + kvp.Key + "_re\" name=\"qty_" + kvp.Key + "_re\" value=\"" + bll.GetAllRequiredQuestionQuantity(courseid, kvp.Key) + "\" >");
                                sb.Append("</div>\r\n");
                            }
                            else
                            {
                                tmplist = bll.GetQuestionIDByCategory(kvp.Key, areaid, courseid, 0, true);
                                tmplist_re = bll.GetQuestionIDByCategory(kvp.Key, areaid, courseid, 1, true);

                                string strIsChecked = string.Empty;
                                string divID = "div_" + kvp.Key;
                                string imgID = "img_" + kvp.Key;
                                sb.Append("<div class=\"data_rows_left\">\r\n");
                                sb.Append("<div class=\"d_r_qt\"><img id=" + imgID + " onclick=\"SetDisplayExamSetting('" + divID + "','" + imgID + "')\" src=\"../../images/icon/arrow_right.gif\" />" + kvp.Value + "</div>\r\n");
                                sb.Append("</div>\r\n");
                                sb.Append("<div id=" + divID + " style=\"display:none\">\r\n");
                                if (tmplist_re != null)
                                {
                                    if (tmplist_re.Count > 0)
                                    {

                                        string divRequireID = "divinner" + divID;
                                        string imgRequireID = "imginner" + imgID;

                                        sb.Append("<div class=\"data_rows_left\">\r\n");
                                        sb.Append("<div  class=\"d_r_qt\">&nbsp;&nbsp;<img id=" + imgRequireID + " onclick=\"SetDisplayExamSetting('" + divRequireID + "','" + imgRequireID + "')\" src=\"../../images/icon/arrow_right.gif\" />必选题</div>\r\n");
                                        sb.Append("</div>\r\n");

                                        sb.Append("<div id=" + divRequireID + "  style=\"display:none\">\r\n");
                                        for (int i = 0; i < tmplist_re.Count; i++)
                                        {
                                            questionIDArr += tmplist_re[i].ID + ",";
                                            sb.Append("<div class=\"data_rows_left\">\r\n");
                                            if (questionIDList != null)
                                            {
                                                if (questionIDList.Contains(tmplist_re[i].ID))
                                                {
                                                    strIsChecked = "checked = 'checked'";
                                                }
                                                else
                                                {
                                                    strIsChecked = "";
                                                }
                                            }
                                            sb.Append("<div class=\"d_r_cusqx\">&nbsp;&nbsp;<input id='chk_" + tmplist_re[i].ID + "' name='chk_" + tmplist_re[i].ID + "' type=\"checkbox\" " + strIsChecked + "/>" + tmplist_re[i].Title + "</div>\r\n");
                                            sb.Append("</div>\r\n");
                                        }
                                        sb.Append("</div>\r\n");

                                    }
                                }
                                if (tmplist != null)
                                {
                                    if (tmplist.Count > 0)
                                    {

                                        string divNoRequireID = "divnorequire" + divID;
                                        string imgNoRequireID = "imgnorequire" + imgID;

                                        sb.Append("<div class=\"data_rows_left\">\r\n");
                                        sb.Append("<div  class=\"d_r_qt\">&nbsp;&nbsp;<img id=" + imgNoRequireID + " onclick=\"SetDisplayExamSetting('" + divNoRequireID + "','" + imgNoRequireID + "')\" src=\"../../images/icon/arrow_right.gif\" />普通题</div>\r\n");
                                        sb.Append("</div>\r\n");

                                        sb.Append("<div id=" + divNoRequireID + "  style=\"display:none\">\r\n");
                                        for (int i = 0; i < tmplist.Count; i++)
                                        {
                                            questionIDArr += tmplist[i].ID + ",";
                                            sb.Append("<div class=\"data_rows_left\">\r\n");

                                            if (questionIDList != null)
                                            {
                                                if (questionIDList.Contains(tmplist[i].ID))
                                                {
                                                    strIsChecked = "checked = 'checked'";
                                                }
                                                else
                                                {
                                                    strIsChecked = "";
                                                }
                                            }
                                            sb.Append("<div class=\"d_r_cusqx\">&nbsp;&nbsp;<input id='chk_" + tmplist[i].ID + "' name='chk_" + tmplist[i].ID + "' type=\"checkbox\" " + strIsChecked + "/>" + tmplist[i].Title + "</div>\r\n");
                                            sb.Append("</div>\r\n");
                                        }
                                        sb.Append("</div>\r\n");
                                    }
                                }
                                sb.Append("</div>\r\n");

                            }
                        }

                        sb.Append("<input type=\"hidden\" id=\"questionidvalue\" name=\"questionidvalue\" value=\"" + questionIDArr + "\" />");
                        sb.Append("<input type=\"hidden\" id=\"categoryvalue\" name=\"categoryvalue\" value=\"" + WebCommon.Convert2String(categoryList) + "\" /><input type=\"hidden\" id=\"coursevalue\" name=\"coursevalue\" />]]>");
                    }
                    break;
                case EnumExamCategory.CertificateExam:
                    sb.Append("&nbsp;");
                    break;
                default:
                    sb.Append("&nbsp;");
                    break;
            }

            sb.Append("</rst>");
            ResponseSimpleXML(sb.ToString());
        }


        private void GetCertificateSettingTemplate(int cid, int id, int questiontype, string questionIDs)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<rst>");
            switch ((EnumExamCategory)cid)
            {
                case EnumExamCategory.CourseExam:
                    sb.Append("&nbsp;");
                    break;
                case EnumExamCategory.CertificateExam:
                    QuestionBLL bll = new QuestionBLL();
                    Dictionary<int, string> categoryList = bll.GetQuestionCategoryList();
                    Dictionary<int, string> courseList = (new CourseBLL()).GetCourseListByCertificateID(id);
                    IList<QuestionModel> tmplist = null;
                    IList<QuestionModel> tmplist_re = null;
                    IList<int> questionIDList = null;
                    string questionIDArr = string.Empty;
                    if (questionIDs != "")
                    {
                        questionIDList = WebCommon.Convert2IList(questionIDs, ',');
                    }

                    if (categoryList.Count > 0)
                    {
                        sb.Append("<![CDATA[");
                        if (questiontype == 1)
                        {
                            foreach (KeyValuePair<int, string> kvp in categoryList)
                            {
                                sb.Append("<div class=\"data_rows\" style=\"font-weight:bolder;\">\r\n");
                                sb.Append("  <div class=\"d_r_qt\">" + kvp.Value + "</div>\r\n");
                                sb.Append("  <div class=\"d_r_qx\"><span class=\"hint\" id=\"total_" + kvp.Key + "\"></span></div>\r\n");
                                sb.Append("  <div class=\"d_r_qq\">&nbsp;</div>\r\n");
                                sb.Append("</div>\r\n");
                                foreach (KeyValuePair<int, string> courseKVP in courseList)
                                {
                                    sb.Append("<div class=\"data_rows\">\r\n");
                                    sb.Append("  <div class=\"d_r_qt\">" + courseKVP.Value + "</div>\r\n");
                                    sb.Append("  <div class=\"d_r_qx\">&nbsp;</div>\r\n");
                                    sb.Append("  <div class=\"d_r_qq\"><input type=\"text\" id=\"input_" + kvp.Key + "_" + courseKVP.Key + "\" name=\"input_" + kvp.Key + "_" + courseKVP.Key + "\" class=\"quantityInput\" /></div>\r\n");
                                    sb.Append("  <div class=\"d_r_qq\"><input type=\"text\" id=\"input_" + kvp.Key + "_" + courseKVP.Key + "_re\" name=\"input_" + kvp.Key + "_" + courseKVP.Key + "_re\" class=\"quantityInput\" /></div>\r\n");
                                    sb.Append("  <div class=\"d_r_qo\">" + bll.GetAllRequiredQuestionQuantity(courseKVP.Key, kvp.Key) + "/" + bll.GetAllQuestionQuantity(courseKVP.Key, kvp.Key) + "</div>\r\n");
                                    sb.Append("</div>\r\n");
                                }
                                sb.Append("<div style=\"width:100%; height:20px;\">&nbsp;</div>\r\n");
                            }
                        }
                        else
                        {
                            foreach (KeyValuePair<int, string> courseKVP in courseList)
                            {
                                int courseid = courseKVP.Key;
                                questionIDArr += ";";
                                sb.Append("<div class=\"data_rows\">" + courseKVP.Value + "</div>\r\n");
                                foreach (KeyValuePair<int, string> kvp in categoryList)
                                {
                                    tmplist = bll.GetQuestionIDByCategory(kvp.Key, areaid, courseid, 0, true);
                                    tmplist_re = bll.GetQuestionIDByCategory(kvp.Key, areaid, courseid, 1, true);

                                    string strIsChecked = string.Empty;
                                    string divID = "div_" + courseid.ToString() + "_" + kvp.Key;
                                    string imgID = "img_" + courseid.ToString() + "_" + kvp.Key;
                                    sb.Append("<div class=\"data_rows_left\">\r\n");
                                    sb.Append("<div class=\"d_r_qt\"><img id=" + imgID + " onclick=\"SetDisplayExamSetting('" + divID + "','" + imgID + "')\" src=\"../../images/icon/arrow_right.gif\" />" + kvp.Value + "</div>\r\n");
                                    sb.Append("</div>\r\n");
                                    sb.Append("<div id=" + divID + " style=\"display:none\">\r\n");
                                    if (tmplist_re != null)
                                    {
                                        if (tmplist_re.Count > 0)
                                        {

                                            string divRequireID = "divinner" + courseid.ToString() + "_" + divID;
                                            string imgRequireID = "imginner" + courseid.ToString() + "_" + imgID;

                                            sb.Append("<div class=\"data_rows_left\">\r\n");
                                            sb.Append("<div  class=\"d_r_qt\">&nbsp;&nbsp;<img id=" + imgRequireID + " onclick=\"SetDisplayExamSetting('" + divRequireID + "','" + imgRequireID + "')\" src=\"../../images/icon/arrow_right.gif\" />必选题</div>\r\n");
                                            sb.Append("</div>\r\n");

                                            sb.Append("<div id=" + divRequireID + "  style=\"display:none\">\r\n");
                                            for (int i = 0; i < tmplist_re.Count; i++)
                                            {
                                                questionIDArr += tmplist_re[i].ID + ",";
                                                sb.Append("<div class=\"data_rows_left\">\r\n");
                                                if (questionIDList != null)
                                                {
                                                    if (questionIDList.Contains(tmplist_re[i].ID))
                                                    {
                                                        strIsChecked = "checked = 'checked'";
                                                    }
                                                    else
                                                    {
                                                        strIsChecked = "";
                                                    }
                                                }

                                                sb.Append("<div class=\"d_r_cusqx\">&nbsp;&nbsp;<input id='chk_" + tmplist_re[i].ID + "' name='chk_" + tmplist_re[i].ID + "' type=\"checkbox\" " + strIsChecked + "/>" + tmplist_re[i].Title + "</div>\r\n");
                                                sb.Append("</div>\r\n");
                                            }
                                            sb.Append("</div>\r\n");

                                        }
                                    }
                                    if (tmplist != null)
                                    {
                                        if (tmplist.Count > 0)
                                        {

                                            string divNoRequireID = "divnorequire" + courseid.ToString() + divID;
                                            string imgNoRequireID = "imgnorequire" + courseid.ToString() + imgID;

                                            sb.Append("<div class=\"data_rows_left\">\r\n");
                                            sb.Append("<div  class=\"d_r_qt\">&nbsp;&nbsp;<img id=" + imgNoRequireID + " onclick=\"SetDisplayExamSetting('" + divNoRequireID + "','" + imgNoRequireID + "')\" src=\"../../images/icon/arrow_right.gif\" />普通题</div>\r\n");
                                            sb.Append("</div>\r\n");

                                            sb.Append("<div id=" + divNoRequireID + "  style=\"display:none\">\r\n");
                                            for (int i = 0; i < tmplist.Count; i++)
                                            {
                                                questionIDArr += tmplist[i].ID + ",";
                                                sb.Append("<div class=\"data_rows_left\">\r\n");

                                                if (questionIDList != null)
                                                {
                                                    if (questionIDList.Contains(tmplist[i].ID))
                                                    {
                                                        strIsChecked = "checked = 'checked'";
                                                    }
                                                    else
                                                    {
                                                        strIsChecked = "";
                                                    }
                                                }
                                                sb.Append("<div class=\"d_r_cusqx\">&nbsp;&nbsp;<input id='chk_" + tmplist[i].ID + "' name='chk_" + tmplist[i].ID + "' type=\"checkbox\" " + strIsChecked + "/>" + tmplist[i].Title + "</div>\r\n");
                                                sb.Append("</div>\r\n");
                                            }
                                            sb.Append("</div>\r\n");
                                        }
                                    }
                                    sb.Append("</div>\r\n");
                                }
                            }
                            sb.Append("<div style=\"width:100%; height:20px;\">&nbsp;</div>\r\n");
                        }
                        sb.Append("<input type=\"hidden\" id=\"questionidvalue\" name=\"questionidvalue\" value=\"" + questionIDArr + "\" />");
                        sb.Append("<input type=\"hidden\" id=\"categoryvalue\" name=\"categoryvalue\" value=\"" + WebCommon.Convert2String(categoryList) + "\" /><input type=\"hidden\" id=\"coursevalue\" name=\"coursevalue\" value=\"" + WebCommon.Convert2String(courseList) + "\" />]]>");
                    }
                    break;
                default:
                    sb.Append("&nbsp;");
                    break;
            }

            sb.Append("</rst>");
            ResponseSimpleXML(sb.ToString());
        }

        private void GetCertificateSurveyReport(int certificateid)
        {
            if (certificateid != -1)
            {
                StringBuilder sb = new StringBuilder();
                SurveyBLL bll = new SurveyBLL();
                //IList<SurveyCategoryAndOptionModel> scaomList = bll.GetCertificateSurveyCategoryList(certificateid);
                CertificateSurveyReportModel reportModel = bll.GetCertificateSurveyReport(certificateid);
                if (reportModel.ID != -1)
                {
                    sb.Append("<Data>\r\n");
                    sb.Append("  <SurveyInfo n=\"" + reportModel.CertificateName + "\">\r\n");
                    foreach (SurveyCategoryAndOptionModel contentModel in reportModel.OptionList)
                    {
                        sb.Append("    <CategoryInfo>\r\n");
                        sb.Append("      <CategoryID>" + contentModel.ID + "</CategoryID>\r\n");
                        sb.Append("      <CategoryName>" + contentModel.CategoryName + "</CategoryName>\r\n");
                        sb.Append("      <Options>\r\n");
                        foreach (KeyValuePair<int, string> kvp in contentModel.OptionList)
                        {
                            sb.Append("        <OptionID>" + kvp.Key + "</OptionID>\r\n");
                            sb.Append("        <OptionName>" + kvp.Value + "</OptionName>\r\n");
                        }
                        sb.Append("      </Options>\r\n");
                        sb.Append("    </CategoryInfo>\r\n");
                    }
                    sb.Append("    <Votes>\r\n");
                    foreach (KeyValuePair<string, string> kvp2 in reportModel.VoteList)
                    {
                        sb.Append("      <Vote>\r\n");
                        sb.Append("        <OptionVote>" + kvp2.Key + "</OptionVote>\r\n");
                        sb.Append("        <CommentVote>" + kvp2.Value + "</CommentVote>\r\n");
                        sb.Append("      </Vote>\r\n");
                    }
                    sb.Append("    </Votes>\r\n");
                    sb.Append("  </SurveyInfo>\r\n");
                    sb.Append("</Data>\r\n");
                    ResponseXML(sb);
                }
            }
        }

        private void GetTotalScore(string categoryarr, string quantityarr)
        {
            try
            {
                string[] categoryArr = categoryarr.Split(',');
                string[] quantityArr = quantityarr.Split(',');

                if (categoryArr.Length == quantityArr.Length)
                {
                    StringBuilder sb = new StringBuilder();
                    QuestionBLL bll = new QuestionBLL();
                    for (int i = 0; i < categoryArr.Length; i++)
                    {
                        int[] total = new int[2] { 0, 0 };
                        sb.Append("<score id=\"" + categoryArr[i] + "\" ");
                        int quantity = Convert.ToInt32(quantityArr[i]);
                        total = bll.GetCurrentTotalScore(Convert.ToInt32(categoryArr[i]), quantity);
                        sb.Append(" total=\"" + total[0] + "\" per=\"" + total[1] + "\" />");
                    }
                    ResponseSimpleXML(sb.ToString());
                }
            }
            catch (Exception ex)
            { }
        }

        private void CheckCourseName(string courseName, int pid, int id)
        {
            bool rst = (new CourseBLL()).CheckExistCourseName(courseName, pid, id);
            if (rst)
            {
                ResponseSimpleXML("1");
            }
            else
            {
                ResponseSimpleXML("0");
            }
        }

        private void CheckInternalPublicCourseName(string courseName, int pid, int id)
        {
            bool rst = (new CourseBLL()).CheckExistPublicCourseName(courseName, pid, id);
            if (rst)
            {
                ResponseSimpleXML("1");
            }
            else
            {
                ResponseSimpleXML("0");
            }
        }

        private void CheckProjectName(string pname, int id)
        {
            bool rst = (new CourseBLL()).CheckExistProjectName(pname, id);
            if (rst)
            {
                ResponseSimpleXML("1");
            }
            else
            {
                ResponseSimpleXML("0");
            }
        }

        private void CheckPublicCourseName(string cname, int id)
        {
            bool rst = (new PublicCourseBLL()).CheckExistCourseName(cname, id);
            if (rst)
            {
                ResponseSimpleXML("1");
            }
            else
            {
                ResponseSimpleXML("0");
            }
        }

        private void CheckScoreCategory(string name, int id)
        {
            bool rst = (new ExamBLL()).CheckExistCategoryName(name, id);
            if (rst)
            {
                ResponseSimpleXML("1");
            }
            else
            {
                ResponseSimpleXML("0");
            }
        }

        private void ResponseSimpleXML(string result)
        {
            StringBuilder xmlnode = new StringBuilder();
            xmlnode.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
            xmlnode.Append("<result>");
            xmlnode.Append(result);
            xmlnode.Append("</result>");
            ResponseXML(xmlnode);
        }

        #region Helper
        /// <summary>
        /// 向页面输出xml内容
        /// </summary>
        /// <param name="xmlnode">xml内容</param>
        private void ResponseXML(System.Text.StringBuilder xmlnode)
        {
            System.Web.HttpContext.Current.Response.Clear();
            System.Web.HttpContext.Current.Response.ContentType = "Text/XML";
            System.Web.HttpContext.Current.Response.Expires = 0;

            System.Web.HttpContext.Current.Response.Cache.SetNoStore();
            System.Web.HttpContext.Current.Response.Write(xmlnode.ToString());
            System.Web.HttpContext.Current.Response.End();
        }

        /// <summary>
        /// 输出json内容
        /// </summary>
        /// <param name="json"></param>
        private void ResponseJSON(string json)
        {
            System.Web.HttpContext.Current.Response.Clear();
            System.Web.HttpContext.Current.Response.ContentType = "application/json";
            System.Web.HttpContext.Current.Response.Expires = 0;

            System.Web.HttpContext.Current.Response.Cache.SetNoStore();
            System.Web.HttpContext.Current.Response.Write(json);
            System.Web.HttpContext.Current.Response.End();
        }

        //private void ResponseJSON<T>(T jsonobj)
        //{
        //    ResponseJSON(JavaScriptConvert.SerializeObject(jsonobj));
        //}
        #endregion
    }
}
